<?php
$device_obj = new device();
$project_obj = new project();
$admin_obj = new admin();

$action_ary = array(
	'getsjno'=>'device_act_sjno', //登录系统后获取挖机编号和线路编号接口  接口
	'getwjno'=>'device_act_wjno'  //获取挖机参数
);



/**
 * 渣车APP登录系统后获取司机接口
 * @author leiqianyong 2018-4-18 14:28 PM 
 */
function device_act_sjno(){
	global $device_obj, $project_obj;

	$rtn = array('state'=>false);
	//得到设备信息
	$no = request('no');    //设备号
	//得到设备信息
	$device_info = $device_obj->device_info_by_no($no);
	if(!$device_info){
		$rtn['code'] = 1104;    //设备不存在
		api_echo_json($rtn);
	}
	$bind_list = $device_obj->bind_list($device_info['id'], array('state'=>1));
	if(!$bind_list){
		$rtn['code'] = 1105;    //设备没有指定项目
		api_echo_json($rtn);
	}
	if(count($bind_list) > 1){
		$rtn['code'] = 1106;    //设备绑定了多个项目
		api_echo_json($rtn);
	}
	$bind_info = $bind_list[0];
	//得到绑定的项目信息
	$project_info = $project_obj->info($bind_info['pid']);
	if($project_info['state'] == 2){
		$rtn['code'] = 1201;    //项目已关闭
		api_echo_json($rtn);
	}

	$result=$device_obj->setinfo_get($project_info['uid'],5);	
	if(empty($result)){
		$_ary = false;		
	}else{
		foreach($result as $val){
			$_ary[]=$val['code'];
		}
	}
	
	$res['sj']=$_ary;
	api_echo_json($res);
}


/**
 * 挖机APP登录系统后获取机手，地块接口
 * @author leiqianyong 2018-4-18 14:28 PM
 */
function device_act_wjno(){
	global $device_obj, $project_obj;
	
	$rtn = array('state'=>false);
	//得到设备信息
	$no = request('no');    //设备号
	//得到设备信息
	$device_info = $device_obj->device_info_by_no($no);
	if(!$device_info){
		$rtn['code'] = 1104;    //设备不存在
		api_echo_json($rtn);
	}
	$bind_list = $device_obj->bind_list($device_info['id'], array('state'=>1));
	if(!$bind_list){
		$rtn['code'] = 1105;    //设备没有指定项目
		api_echo_json($rtn);
	}
	if(count($bind_list) > 1){
		$rtn['code'] = 1106;    //设备绑定了多个项目
		api_echo_json($rtn);
	}
	$bind_info = $bind_list[0];
	//得到绑定的项目信息
	$project_info = $project_obj->info($bind_info['pid']);
	if($project_info['state'] == 2){
		$rtn['code'] = 1201;    //项目已关闭
		api_echo_json($rtn);
	}
	
	$result=$device_obj->setinfo_get($project_info['uid']);
	if(empty($result)){
		$rtn['code'] = 1202;
		api_echo_json($rtn);		
	}
	
	foreach($result as $val){
		$_ary[$val['type']][]=$val['code'];
	}
		
	if(empty($_ary[3])){		  
		$_ary[3]=false;	 //机手编号未设置	
	}
	
	if(empty($_ary[4])){		
		$_ary[4]=false; //地块编号未设置
	}	
	$res['js']=$_ary[3];
	$res['dk']=$_ary[4];
	api_echo_json($res);
}


	
?>